
#include "nbt_tag.h"
#include <stdlib.h>

#define PTRSZ sizeof(void*)

const char *tag_type_names[] = {
	"TAG_end",
	"TAG_byte",
	"TAG_short",
	"TAG_int",
	"TAG_long",
	"TAG_float",
	"TAG_double",
	"TAG_byte_array",
	"TAG_string",
	"TAG_list",
	"TAG_compound",
};


tag_t tag_new(int ttype)
{
	tag_t nt;
	switch(ttype)
	{
	case TT_END:
		break;

	case TT_BYTE:	nt = malloc(PTRSZ+1+1); break;
	case TT_SHORT:	nt = malloc(PTRSZ+1+2); break;
	case TT_INT:	nt = malloc(PTRSZ+1+4); break;
	case TT_LONG:	nt = malloc(PTRSZ+1+sizeof(long)); break;
	case TT_FLOAT:	nt = malloc(PTRSZ+1+sizeof(float)); break;
	case TT_DOUBLE:	nt = malloc(PTRSZ+1+sizeof(double)); break;
	case TT_BARRAY: //same as string
	case TT_STRING:	//same as list
	case TT_LIST:	//same as compound
	case TT_COMPD:	nt = malloc(sizeof(struct _tag)); break;
	default:
		/*TODO error*/
		break;
	}
	nt->type = ttype;
	return nt;
}

